<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <div id="app">
        <div>
            <p>
                名称: <input v-model="nameItem" type="text">
            </p>
            <p>
                数量: <input v-model="numItem" type="text">
            </p>
        </div>
        <div ref="main" style="width: 600px;height:400px;"></div>
        <button @click="change('bar')">柱状图</button>
        <button @click="change('line')">折线图</button>

        <div>
            <button @click="push">添加</button>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script crossorigin="anonymous"
        integrity="sha512-CNXD81ugRg68yNQQ9TSlZb/pLzbJ5Xo+QRQhIKxW7U3wwYOTcb9O0Q+3yWiWvwBElV/z7oo0hlqOqxPyMbZ8zQ=="
        src="https://lib.baomitu.com/echarts/5.3.3/echarts.common.js"></script>
    <script>
        new Vue({
            // 元素
            el: "#app",
            // 定义的数据(状态)
            data: {
                nameItem: "",
                numItem: "",
                type: "bar",
                name: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子'],
                num: [5, 20, 36, 10, 10, 20]
            },
            created() {
                // axios.get('url').then(res => {
                //     this.list = res.data
                // })
            },
            // 页面挂载完成
            mounted() {
                this.init()
            },

            // created  10    英语
            // mounted  20    英语
            
            methods: {
                push() {
                    this.name.push(this.nameItem)
                    this.num.push(this.numItem)
                    this.init()
                },
                init() {
                    var myChart = echarts.init(this.$refs.main)
                    // 指定图表的配置项和数据
                    var option = {
                        title: {
                            text: 'ECharts 入门示例'
                        },
                        tooltip: {},
                        legend: {
                            data: ['销量']
                        },
                        xAxis: {
                            data: this.name
                        },
                        yAxis: {},
                        series: [
                            {
                                name: '销量',
                                type: this.type,
                                data: this.num
                            }
                        ]
                    };

                    // 使用刚指定的配置项和数据显示图表。
                    myChart.setOption(option);
                },
                change(type) {
                    this.type = type
                    this.init()
                }
            }
        })
    </script>
</body>

</html>